﻿using JustCleanIt.Database;
using JustCleanIt.DataStructure;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;

namespace JustCleanIt.WebService
{
    [AspNetCompatibilityRequirements(
        RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class CustomerService : ICustomerService
    {
        static ICustomerRepository repository = new CustomerRepository();

        public List<Customer> GetAllCustomers()
        {
            return repository.GetAllCustomers();
        }

        public Customer GetCustomerByName(string name)
        {
            return repository.GetCustomerByName(name);
        }

        public string AddCustomer(Customer customer, string password2)
        {
            string result = string.Empty;

            result = repository.AddNewCustomer(customer, password2);

            return result;
        }

        public string UpdateCustomer(Customer customer, string name)
        {
            bool updated = repository.UpdateACustomer(customer);
            if (updated)
                return "Customer with name = " + name + " updated successfully";
            else
                return "Unable to update Customer with name = " + name;

        }

        public string CheckCustomerExist(string email)
        {
            bool result = repository.IsCustomerRegistered(email);
            if (result)
            {
                return "Customer with email = " + email + " already registered";
            }
            else
            {
                return "Customer with email = " + email + " does not exist";
            }
        }

        public string DeleteCustomer(string name)
        {
            bool deleted = repository.DeleteACustomer(name);
            if (deleted)
                return "Customer with name = " + name + " deleted successfully.";
            else
                return "Unable to delete customer with name = " + name;
        }
    }
}
